/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package sessao;

import entidade.LoginUsuario;
import java.util.List;
import javax.ejb.Stateless;
import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;

/**
 *
 * @author bruno
 */
@Stateless
public class LoginUsuarioFacade extends AbstractFacade<LoginUsuario> {
    @PersistenceContext(unitName = "PROINPU")
    private EntityManager em;

    protected EntityManager getEntityManager() {
        return em;
    }

    public LoginUsuarioFacade() {
        super(LoginUsuario.class);
    }
    
    @Override
    public List<LoginUsuario> findAll() {
        return em.createNamedQuery("LoginUsuario.findAll").getResultList();
    }
    
    @Override
    public List<LoginUsuario> findRange(int[] range) {
      /* sql puro
        javax.persistence.Query q = em.createNativeQuery(
                "SELECT * FROM login_usuario "
                + "ORDER BY nomeUsuario "
                + "LIMIT " + range[0] + " , " + (range[1]-range[0]) ); 
      */ 

                /* criteria query
        q.setMaxResults(range[1] - range[0]);
        q.setFirstResult(range[0]);
        
        cq.orderBy(getEntityManager().getCriteriaBuilder().asc("nomeUsuario"));
        */
        
        javax.persistence.Query q = em.createQuery(
                "SELECT l FROM LoginUsuario l "
                + "ORDER BY l.nomeUsuario ASC");
        q.setMaxResults(range[1] - range[0]);
        q.setFirstResult(range[0]);
       
        return q.getResultList();

    }
    
    
        
    
}
